// pages/movieinfo/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movieinfo: {},
    limit: true,
    avatar: '',
    actorList: [],
    maoyanInfo: [],
    maoyanCelebrities: [],
    hcmts: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var page = this;
    if (options.maoyanid) {
      wx.request({
        url: 'https://wx.maoyan.com/hostproxy/mmdb/movie/v5/'+options.maoyanid+'.json?ci=20',
        header: {
          'x-host': 'http://maoyanapi.vip.sankuai.com'
        },
        success(res) {
          page.setData({
            maoyanInfo: res.data.data.movie
          })
        }
      })
      wx.request({
        url: 'https://wx.maoyan.com/hostproxy/mmdb/v7/movie/'+options.maoyanid+'/celebrities.json',
        header: {
          'x-host': 'http://maoyanapi.vip.sankuai.com'
        },
        success(res) {
          page.setData({
            maoyanCelebrities: res.data.data
          })          
        }
      })
      wx.request({
        url: 'https://wx.maoyan.com/hostproxy/mmdb/comments/movie/v2/'+options.maoyanid+'.json?limit=6',
        header: {
          'x-host': 'http://maoyanapi.vip.sankuai.com'
        },
        success(res) {
          page.setData({
            hcmts: res.data.hcmts
          })
          
        }
      })
    }
    this.setData({
      // avatar: app.globalData.userInfo.avatarUrl
    })
    var myThis = this;
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('movieinfo', function (data) {
      myThis.setData({
        movieinfo: data.movieinfo
      })
      wx.request({
        url: app.globalData.url + '/wechatapi/actorlist/?id=' + myThis.data.movieinfo.id,
        success(res) {
          myThis.setData({
            actorList: res.data
          })
        }
      })
    })
  },
  islimit: function () {
    this.setData({
      limit: !this.data.limit,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})